package com.xiaoyi.intentsdklibrary.Utils;

import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract;
import com.xiaoyi.intentsdklibrary.Bean.PhoneBean;
import java.util.ArrayList;
import java.util.List;

public class PhoneNumUtil {
    public static List<PhoneBean> getPhoneData(Context context) {
        ArrayList arrayList = new ArrayList();
        try {
            Cursor query = context.getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
            if (query != null) {
                while (query.moveToNext()) {
                    String string = query.getString(query.getColumnIndex("_id"));
                    String string2 = query.getString(query.getColumnIndex("display_name"));
                    ContentResolver contentResolver = context.getContentResolver();
                    Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
                    Cursor query2 = contentResolver.query(uri, null, "contact_id=" + string, null, null);
                    if (query2 != null) {
                        while (query2.moveToNext()) {
                            String string3 = query2.getString(query2.getColumnIndex("data1"));
                            PhoneBean phoneBean = new PhoneBean();
                            phoneBean.setUserName(string2);
                            phoneBean.setPhoneNum(string3);
                            arrayList.add(phoneBean);
                        }
                        query2.close();
                    }
                }
                query.close();
            }
            return arrayList;
        } catch (Exception e) {
            e.printStackTrace();
        } catch (Throwable unused) {
        }
        return arrayList;
    }
}
